package com.hmall.cart.listener;

import com.hmall.cart.service.ICartService;
import com.hmall.common.constants.MqConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
@Slf4j
public class CartRemoveListener {
    @Autowired
    private ICartService cartService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(MqConstants.TRADE_SUCCESS_QUEUE),
            exchange = @Exchange(MqConstants.TRADE_EXCHANGE_NAME),
            key = MqConstants.TRADE_SUCCESS_KEY
    ))
    public void listener(Collection<Long> itemIds) {
        log.info("清空购物车的中的商品，商品ids为：{}", itemIds);
        cartService.removeByItemIds(itemIds);
    }
}
